﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.tree {

    public class TreePath {

        private var parentPath:TreePath;
        private var lastPathComponent;

        public function TreePath(_arg1:Array){
            var _local2:Array;
            super();
            if ((((_arg1 == null)) || ((_arg1.length == 0)))){
                trace("Error : path in TreePath must be non null and not empty.");
                throw (new Error("path in TreePath must be non null and not empty."));
            };
            this.lastPathComponent = _arg1[(_arg1.length - 1)];
            if (_arg1.length > 1){
                _local2 = _arg1.concat();
                _local2.pop();
                this.parentPath = new TreePath(_local2);
            };
        }
        public static function createTreePath(_arg1:TreePath, _arg2):TreePath{
            if (_arg2 == null){
                trace("path in TreePath must be non null.");
                throw (new Error("path in TreePath must be non null."));
            };
            var _local3:TreePath = new TreePath([null]);
            _local3.parentPath = _arg1;
            _local3.lastPathComponent = _arg2;
            return (_local3);
        }

        public function getPath():Array{
            var _local1:Number = this.getPathCount();
            var _local2:Array = new Array(_local1);
            _local1--;
            var _local3:TreePath = this;
            while (_local3 != null) {
                _local2[_local1] = _local3.lastPathComponent;
                _local1--;
                _local3 = _local3.parentPath;
            };
            return (_local2);
        }
        public function getLastPathComponent(){
            return (this.lastPathComponent);
        }
        public function getPathCount():int{
            var _local1:Number = 0;
            var _local2:TreePath = this;
            while (_local2 != null) {
                _local1++;
                _local2 = _local2.parentPath;
            };
            return (_local1);
        }
        public function getPathComponent(_arg1:int){
            var _local2:int = this.getPathCount();
            if ((((_arg1 < 0)) || ((_arg1 >= _local2)))){
                return (undefined);
            };
            var _local3:TreePath = this;
            var _local4:int = (_local2 - 1);
            while (_local4 != _arg1) {
                _local3 = _local3.parentPath;
                _local4--;
            };
            return (_local3.lastPathComponent);
        }
        public function equals(_arg1):Boolean{
            var _local2:TreePath;
            var _local3:TreePath;
            if (_arg1 == this){
                return (true);
            };
            if ((_arg1 is TreePath)){
                _local2 = TreePath(_arg1);
                if (this.getPathCount() != _local2.getPathCount()){
                    return (false);
                };
                _local3 = this;
                while (_local3 != null) {
                    if (_local3.lastPathComponent != _local2.lastPathComponent){
                        return (false);
                    };
                    _local2 = _local2.parentPath;
                    _local3 = _local3.parentPath;
                };
                return (true);
            };
            return (false);
        }
        public function isDescendant(_arg1:TreePath):Boolean{
            var _local2:Number;
            var _local3:Number;
            if (_arg1 == this){
                return (true);
            };
            if (_arg1 != null){
                _local2 = this.getPathCount();
                _local3 = _arg1.getPathCount();
                if (_local3 < _local2){
                    return (false);
                };
                while (_local3 > _local2) {
                    _arg1 = _arg1.getParentPath();
                    _local3--;
                };
                return (this.equals(_arg1));
            };
            return (false);
        }
        public function pathByAddingChild(_arg1):TreePath{
            if (_arg1 == null){
                trace("Null child not allowed");
                throw (new Error("Null child not allowed"));
            };
            return (createTreePath(this, _arg1));
        }
        public function getParentPath():TreePath{
            return (this.parentPath);
        }
        public function toString():String{
            return ((("TreePath[" + this.getPath()) + "]"));
        }

    }
}//package org.aswing.tree 
